package com.ybkj.daijia.api.common.responseBody;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;

public class ResponseResult implements Serializable {

    private static final long serialVersionUID = 1L;

    private int code;

    private String message;

    private Object data;

    public ResponseResult() {}

    public ResponseResult(Response response) {
        this.code = response.getCode();
        this.message = response.getMessage();
    }

    public ResponseResult(Response response, Object data) {
        this.code = response.getCode();
        this.message = response.getMessage();
        this.data = data;
    }

    @JsonIgnore
    public static ResponseResult getErrorBy(Response response) {
        ResponseResult instance = new ResponseResult();
        instance.setCode(response.getCode());
        instance.setMessage(response.getMessage());
        return instance;
    }

    public String getResultJsonString(){
        JSONObject result = new JSONObject();
        result.put("code", this.code);
        result.put("message", this.message);
        result.put("data", this.data);
        System.out.println("{code:"+code+", message:"+message+", data:"+data+"}");
        String str = JSONObject.toJSONString(result);
        System.out.println(str);
        return str;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultTransport{"
            + "code:" + code + ", "
            + "message:" + message + ", "
            + "data:" + data +
            '}';
    }
}
